package com.eight.vote.controller;


import com.eight.vote.pojo.VMessage;
import com.eight.vote.pojo.VOption;
import com.eight.vote.service.VMessageService;
import com.eight.vote.util.Result;
import com.eight.vote.vo.VoteVo;
import com.eight.vote.vo.GetVoteVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 点点星言
 * @since 2022-10-16
 */
@RestController
@RequestMapping("/api/vote")
@Slf4j
public class VMessageController {
    @Autowired
    VMessageService messageService;

    /**
     * 获取展示在首页的热门的投票活动
     * @return
     */
    @GetMapping("index/{pageNum}/{pageSize}")
    public Result getIndex(
            @PathVariable("pageNum") Integer pageNum,
            @PathVariable("pageSize") Integer pageSize
            ){
        return messageService.getHotVote(pageNum,pageSize);
    }

    /**
     * 添加投票信息接口
     * @param voteVo
     * @return
     */
    @PostMapping("addVote")
    public Result addVote(@RequestBody VoteVo voteVo){
        return messageService.addVote(voteVo);
    }

    @PostMapping("userAddVote")
    public Result userAddVote(@RequestBody VOption option){
        return messageService.userAddVote(option);
    }

    @PostMapping("search/{pageNum}/{pageSize}")
    public Result searchVote(String keyword,
                             @PathVariable("pageNum") Integer pageNum,
                             @PathVariable("pageSize") Integer pageSize
                             ){
        log.debug(keyword);
        return messageService.searchVote(keyword,pageNum,pageSize);
    }

    @PostMapping("getVoteById")
    public Result getVoteById(@RequestBody GetVoteVo getVoteVo){
        return messageService.getVoteById(getVoteVo);
    }

    @GetMapping("getVoteByUserId/{pageNum}/{pageSize}")
    public Result getVoteByUserId( @PathVariable("pageNum") Integer pageNum,
                                   @PathVariable("pageSize") Integer pageSize
    ){
        return messageService.getVoteByUserId(pageNum,pageSize);
    }

    @PostMapping("deleteMessage")
    public Result deleteMessage(@RequestBody VMessage message){
        return messageService.deleteMessage(message.getMsgId());
    }


}

